home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / src / wcore.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-17  |  5.1 KB  |  186 lines

  1. /*
  2.  *  Window Maker window manager
  3.  * 
  4.  *  Copyright (c) 1997, 1998 Alfredo K. Kojima
  5.  * 
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
  19.  *  USA.
  20.  */
  21.  
  22. #include "wconfig.h"
  23.  
  24. #include <X11/Xlib.h>
  25. #include <X11/Xutil.h>
  26.  
  27. #include <stdlib.h>
  28. #include <string.h>
  29.  
  30. #include "WindowMaker.h"
  31. #include "wcore.h"
  32.  
  33.  
  34. /****** Global Variables ******/
  35. extern WPreferences wPreferences;
  36.  
  37. /* cursors */
  38. extern Cursor wCursor[WCUR_LAST];
  39.  
  40. extern XContext wWinContext;
  41.  
  42.  
  43. /*
  44.  *----------------------------------------------------------------------
  45.  * wCoreCreateTopLevel--
  46.  *     Creates a toplevel window used for icons, menus and dialogs.
  47.  *
  48.  * Returns:
  49.  *     The created window.
  50.  *----------------------------------------------------------------------
  51.  */
  52. WCoreWindow*
  53. wCoreCreateTopLevel(WScreen *screen, int x, int y, int width, int height,
  54.             int bwidth)
  55. {
  56.     WCoreWindow *core;
  57.     int vmask;
  58.     XSetWindowAttributes attribs;
  59.  
  60.     core = wmalloc(sizeof(WCoreWindow));
  61.     memset(core, 0, sizeof(WCoreWindow));
  62.  
  63.     vmask = /*CWBackPixmap|*/CWBackPixel|CWBorderPixel|CWCursor|CWEventMask
  64.       |CWOverrideRedirect;
  65.     attribs.override_redirect = True;
  66.     attribs.cursor = wCursor[WCUR_DEFAULT];
  67.     attribs.background_pixmap = None;
  68.     attribs.background_pixel = screen->black_pixel;
  69.     attribs.border_pixel = screen->frame_border_pixel;
  70.     attribs.event_mask = SubstructureRedirectMask | ButtonPressMask
  71.         | ButtonReleaseMask | ButtonMotionMask | ExposureMask | EnterWindowMask
  72.         | LeaveWindowMask;
  73.  
  74.     vmask |= CWColormap;
  75.     attribs.colormap = screen->w_colormap;
  76.  
  77.     core->window = XCreateWindow(dpy, screen->root_win, x, y, width, height,
  78.                  bwidth, screen->w_depth, CopyFromParent,
  79.                  screen->w_visual, vmask, &attribs);
  80.     core->width = width;
  81.     core->height = height;
  82.     core->screen_ptr = screen;
  83.  
  84.     core->descriptor.self = core;
  85.     
  86.     XClearWindow(dpy, core->window);
  87.  
  88.     XSaveContext(dpy, core->window, wWinContext, (XPointer)&core->descriptor);
  89.  
  90.     return core;
  91. }
  92.  
  93.  
  94. /*
  95.  *---------------------------------------------------------------------- 
  96.  * wCoreCreate--
  97.  *     Creates a brand new child window.
  98.  *     The window will have a border width of 0 and color is black.
  99.  * 
  100.  * Returns:
  101.  *     A initialized core window structure.
  102.  * 
  103.  * Side effects:
  104.  *     A window context for the created window is saved.
  105.  * 
  106.  * Notes:
  107.  *     The event mask is initialized to a default value.
  108.  * 
  109.  *---------------------------------------------------------------------- 
  110.  */
  111. WCoreWindow*
  112. wCoreCreate(WCoreWindow *parent, int x, int y, int width, int height)
  113. {
  114.     WCoreWindow *core;
  115.     int vmask;
  116.     XSetWindowAttributes attribs;
  117.  
  118.     core=wmalloc(sizeof(WCoreWindow));
  119.     memset(core, 0, sizeof(WCoreWindow));
  120.  
  121.     vmask = CWBackPixmap|CWBackPixel|CWBorderPixel|CWCursor|CWEventMask;
  122.     attribs.cursor = wCursor[WCUR_DEFAULT];
  123.     attribs.background_pixmap = None;
  124.     attribs.background_pixel = parent->screen_ptr->black_pixel;
  125.     attribs.event_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask
  126.       | ButtonReleaseMask | ButtonMotionMask | ExposureMask | EnterWindowMask
  127.       | LeaveWindowMask;
  128.     /*
  129.     vmask |= CWColormap;
  130.     attribs.colormap = parent->screen_ptr->w_colormap;
  131.      */
  132.     core->window =
  133.       XCreateWindow(dpy, parent->window, x, y, width, height, 0,
  134.             parent->screen_ptr->w_depth, CopyFromParent,
  135.             parent->screen_ptr->w_visual, vmask, &attribs);
  136.     core->width=width;
  137.     core->height=height;
  138.     core->screen_ptr = parent->screen_ptr;
  139.  
  140.     core->descriptor.self = core;
  141.  
  142.     XSaveContext(dpy, core->window, wWinContext, (XPointer)&core->descriptor);
  143.     return core;
  144. }
  145.  
  146.  
  147.  
  148. void
  149. wCoreDestroy(WCoreWindow *core)
  150. {
  151.     if (core->stacking) {
  152.     free(core->stacking);
  153.     }
  154.     XDeleteContext(dpy, core->window, wWinContext);
  155.     XDestroyWindow(dpy, core->window);
  156.     free(core);
  157. }
  158.  
  159.  
  160. void
  161. wCoreConfigure(WCoreWindow *core, int req_x, int req_y, int req_w, int req_h)
  162. {
  163.     XWindowChanges xwc;
  164.     unsigned int mask;
  165.     
  166.     mask = CWX|CWY;
  167.     xwc.x = req_x;
  168.     xwc.y = req_y;
  169.     
  170.     if (req_w <= 0) 
  171.       req_w = core->width;
  172.     if (req_h <= 0)
  173.       req_h = core->height;
  174.     
  175.     if (req_w != core->width || req_h != core->height) {
  176.     mask |= CWWidth | CWHeight;
  177.     xwc.width = req_w;
  178.     xwc.height = req_h;
  179.     core->width = req_w;
  180.     core->height = req_h;
  181.     }
  182.     XConfigureWindow(dpy, core->window, mask, &xwc);
  183. }
  184.  
  185.  
  186.